\chapter{Related Work}

Research has been carried out for many years to improve the process of retargeting GCC. Some of the topics of interest are, coming up with a methodology
that can systematically build MD files, improving the way machine descriptions are written, and automating the process of writing machine description files.


Khedker et al., proposed a new language specRTL\cite{Khedker} to eliminate the redundancies found in GCC's machine description 
files. Our work is largely inspired by this work. 

\begin{itemize}
 \item specRTL is a simplified language to allow users to write MD files easily with fewer redundancies.
 \item specRTL is not suitable to discover redundancies in existing MD files.
\end{itemize}

Our tool on the other hand is intended to be used by users to discover and minimize redundancies in MD files which in turn
can be helpful in retargeting.


Sameera et al.\cite{Sameera} proposed a systematic way to build GCC machine descriptions. They have split the process of building machine 
descriptions into five steps. As the first step, handling simple assignment statements. Further steps successively handle
arithmetic operations, function calls, conditional control transfers and other data type handling respectively in that order. The motivation 
for this work is to develop a working compiler at every step that can handle a restricted subset of the input language. This subset grows with 
successive steps.

Kai-Wei Lin et al.\cite{kai-wei}  work discusses about a systematic methodology, to port GCC to a new architecture. This work is very similar in nature
to the work by Sameera et al. \cite{Sameera}. They have
split the process of writing Machine Description files into seven steps. The first step involves modifying the configuration
files of the target machine. Further steps involve adding functionalities to handle integer assignment, function call support,
conditional branches and handling other data types. The final step involves adding optional optimization routines.
Based on this methodology, they have built a tool that assists in porting. They have implemented a web based tool, that acts as a wizard and guides
the user in each of the steps by providing templates relevant for the current step.


Both the above cited works suggested a systematic way to build MD files. But no attempt was made to simplify it by using existing MD files.
Our work, unlike the above works, gives the flexibility to choose the architectures that we feel that the new architecture is similar to. Then
we can use the tool developed to extract the patterns from them. So, the minimal set provided is not fixed and it can be
changed by choosing the machines of interest and restrict it only to them, thereby the minimal set allows the user to 
focus only on those patterns that matters and not a universal set.This helps in making the decision process simpler. 

The final goal of our work is to generate MD files using MD files of existing MD files. This thesis is the first step in our long term goal. Here we have 
studied existing MD files and developed tools to understand similarities between architectures. In particular, our work allows reuse of patterns from existing
MD files in new MD files. The user is benefited, as patterns are shared between machines, by modifying few patterns, new MD files can be constructed.

In summary, our work is a starting point to convert existing MD files to a specRTL like specification. This specification can be modified by the user to
generate MD files for new architecture. We expect the size of new MD files written using this specification to be much smaller and therefore easier to 
modify these files than the current MD files with full specification.



C.Colberg's \cite{Collberg} work makes understanding the architectural features of a new architecture easier by
using the native C compiler. A prototype tool, Architecture Discovery Tool(ADT) was created, which generates a formal
machine description, which can be used by a back end generator to get a native code generator. The ADT, runs simple
C or FORTRAN programs on the target machine, and discovers instruction set, addressing modes, calling conventions, etc.
The method used by ADT to do this is called Self-Retargeting Code Generation. One important constraint this work places is that the
target architecture should have a native compiler already available, which is not always possible.








